from django.db import models

from utils.basemodel import BaseModel


# Create your models here.

class CateModel(BaseModel):
    c_name = models.CharField(max_length=20,verbose_name='分类名称')
    parent = models.ForeignKey('self',on_delete=models.CASCADE,blank=True, null=True,verbose_name='上级分类',related_name='children')
    is_hot = models.BooleanField(default=False,verbose_name='是否热门')
    is_good = models.BooleanField(default=False,verbose_name='是否精品')
    is_home = models.BooleanField(default=False,verbose_name='是否展示在首页')

    class Meta:
        db_table = 'fgcategroy'

    def __str__(self):
        return self.c_name

class TeacherModel(BaseModel):
    t_name = models.CharField(max_length=50,verbose_name='教师名称')
    job = models.CharField(max_length=50,verbose_name='职位')
    intro = models.TextField(verbose_name='简介')
    headimg = models.ImageField(upload_to='uploads',verbose_name='头像')

    class Meta:
        db_table = 'fgteacher'

    def __str__(self):
        return self.t_name

class CourseModel(BaseModel):
    c_name = models.CharField(max_length=50,verbose_name='课程名称')
    category = models.ForeignKey(CateModel,on_delete=models.CASCADE,verbose_name='课程分类')
    teacher = models.ForeignKey(TeacherModel,on_delete=models.CASCADE,verbose_name='授课教师')
    cover = models.ImageField(upload_to='uploads',verbose_name='封面')
    level = models.IntegerField(choices=(('1','初级'),('2','中级'),('3','高级')),verbose_name='难度等级',default=1)
    vedio = models.CharField(max_length=200,verbose_name='视频')
    price = models.DecimalField(max_digits=5,decimal_places=2,verbose_name='价格')
    discount = models.DecimalField(max_digits=5,decimal_places=2,verbose_name='折扣价')
    ishome = models.BooleanField(default=False,verbose_name='是否推荐')
    ishot = models.BooleanField(default=False,verbose_name='是否热门')
    read = models.IntegerField(default=0,verbose_name='阅读量')
    content = models.TextField(default='暂无',verbose_name='课程内容')

    class Meta:
        db_table = 'fgcourse'

    def __str__(self):
        return self.c_name
